package com.atguigu.srb.core.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName: FillTimeObjectHandler
 * Package: com.atguigu.srb.core.handler
 * Description:
 *
 * @Author 王晓龙
 * @Create 2023/3/25 21:07
 * @Version 1.0
 */
@Component
public class FillTimeObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.hasSetter("createTime")){
            metaObject.setValue("createTime", new Date());
        }
        if (metaObject.hasSetter("updateTime")){
            metaObject.setValue("updateTime", new Date());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if (metaObject.hasSetter("updateTime")){
            metaObject.setValue("updateTime", new Date());
        }
    }
}
